﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace MidiPlayer
{
    [Serializable]
    public class MidiSettingsDto : ISerializable
    {
        public string MidiInName;
        public string MidiOutName;
        public int MidiOutChannel;
        public int MidiPlayNote;
        public bool StopOnNoteRelease;
        public OutputMode MidiMode;

        public enum OutputMode
        {
            Invalid = 0,
            PassThru,
            PlayFile,

        }

        public MidiSettingsDto()
        {
            MidiMode = OutputMode.Invalid;
            MidiOutChannel = 1;
            StopOnNoteRelease = false;
        }

       #region ISerializable Members

        public MidiSettingsDto(SerializationInfo info, StreamingContext ctxt)
        {
            MidiMode = (OutputMode)info.GetValue("MidiMode", typeof(OutputMode));
            MidiOutChannel = (int)info.GetValue("MidiOutChannel", typeof(int));
            MidiPlayNote = (int)info.GetValue("MidiPlayNote", typeof(int));
            MidiInName = (string)info.GetValue("MidiInName", typeof(string));
            MidiOutName = (string)info.GetValue("MidiOutName", typeof(string));
            StopOnNoteRelease = (bool)info.GetValue("StopOnNoteRelease", typeof(bool));
            
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("MidiMode", this.MidiMode);
            info.AddValue("MidiOutChannel", this.MidiOutChannel);
            info.AddValue("MidiPlayNote", this.MidiPlayNote);
            info.AddValue("MidiInName", this.MidiInName);
            info.AddValue("MidiOutName", this.MidiOutName);
            info.AddValue("StopOnNoteRelease", this.StopOnNoteRelease);
        }

        #endregion

        public string GetDisplaySettings()
        {
            String Settings = String.Empty;
            if(MidiMode == OutputMode.PassThru)
            {
                Settings = MidiInName + " => " + "(" + MidiOutChannel + ")" + MidiOutName ;
            } else if(MidiMode == OutputMode.PlayFile)
            {
                if(StopOnNoteRelease)
                    Settings = @"Play\Stop from" + MidiInName;
                else 
                    Settings = "Play from" + MidiInName;
            }
            else
            {
                Settings = "! Not configured";
            }
            return Settings;
        }
    }
}
